<template>
  <div class="item item-show" :class="{ 'item-closed': !dataInfo.opened }">
    <div class="item-top" @click="handleOpen">
      <div class="level">
        <NuxtImg :src="dataInfo.icon" />
      </div>
      <p class="label">
        {{ lang.invest_and_obtain_1 }} {{ dataInfo.data_1 }}
        {{ lang.invest_and_obtain_2 }}
        <span class="amount"> {{ dataInfo.data_2 }}</span>
      </p>
      <div class="right">
        <div class="btn" @click.stop="handleBuy">{{ lang.buy_btn }}</div>
        <NuxtImg class="right-img" src="/images/layout/icon-jtLeft.png" />
      </div>
    </div>
    <div class="item-details">
      <div class="table">
        <div class="table-header">
          <div class="first-one">{{ lang.table_time }}</div>
          <div class="middle">{{ lang.table_amount }}</div>
          <div>{{ lang.table_bar }}</div>
        </div>
        <div v-for="day in dataInfo.list" :key="day.day" class="table-item">
          <div class="first-one">{{ lang.day_prefix }} {{ day.day }}</div>
          <div class="middle">{{ userStore.moneyUnit }} {{ day.amount }}</div>
          <div>{{ day.bar }}</div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
const lang: any = getCurrentPageLang("activity/days-cards");
const userStore = useUserStore();

const props = defineProps(["dataInfo"]);
const emit = defineEmits(["changeDepDialog"]);

function handleBuy() {
  emit("changeDepDialog", true, props.dataInfo.data_1);
}

function handleOpen() {
  props.dataInfo.opened = !props.dataInfo.opened;
}
</script>

<style scoped lang="scss">
.item {
  width: 100%;
  margin-top: 0.3rem;
  display: flex;
  flex-direction: column;
  background: var(--theme-color4);
  border-radius: 0.3rem;
  color: #fff;

  .item-top {
    width: 100%;
    height: 1.3rem;
    display: flex;
    align-items: center;
    border-radius: 0.3rem;
    position: relative;
    z-index: 1;

    .level {
      width: 0.8rem;
      height: 0.8rem;
      margin-left: 0.18rem;

      img {
        width: 0.8rem;
        height: 0.8rem;
      }
    }

    .label {
      font-family: Arial;
      font-weight: 700;
      margin-left: 0.25rem;
      margin-right: 0.45rem;
      font-size: 0.38rem;

      .amount {
        color: var(--theme-dec4);
      }
    }

    .right {
      position: absolute;
      display: flex;
      align-items: center;
      right: 0.2rem;

      .btn {
        height: 0.8rem;
        background: linear-gradient(
          360deg,
          var(--theme-main-gradient1) 0%,
          var(--theme-main-gradient2) 81%
        );
        border-radius: 2rem;
        box-sizing: border-box;
        padding: 0 0.4rem;
        font-family: Arial;
        font-weight: 600;
        font-size: var(--font-title2);
        text-align: center;
        line-height: 0.8rem;
        color: var(--font-color11);
        right: 0.2rem;
      }

      img {
        width: 0.5rem;
        height: 0.5rem;
        transform: rotate(90deg);
        margin-left: 0.3rem;
        opacity: 0.6;
        transition: all 0.2s;
      }

      .right-img {
        transition: all 0.2s;
      }
    }
  }

  &.item-show .item-top {
    border-radius: 0.3rem 0.3rem 0rem 0rem !important;
    background: var(--secondary-color);
  }

  .item-details {
    transition: all 0.5s;
    width: 100%;
    z-index: 0;
    transition: all 0.2s;
    max-height: 8rem;
    border-radius: 0.3rem 0 0 0.3rem;
    overflow: hidden;

    .table {
      border-radius: 0rem 0rem 0.3rem 0.3rem;
      opacity: 0.8;

      .table-header {
        display: flex;
        height: 1rem;
        background: linear-gradient(
          90deg,
          var(--theme-ts2-gradient1) 0%,
          var(--theme-ts2-gradient2) 100%
        );
        border-radius: 0.3rem 0.3rem 0rem 0rem;

        > div {
          text-align: center;
          line-height: 0.9rem;
          width: 30%;

          &.first-one {
            width: 20%;
          }

          &.middle {
            width: 50%;
          }
        }
      }

      .table-item {
        display: flex;
        width: 100%;
        height: 1rem;
        box-sizing: border-box;
        padding: 0 0.5rem;
        background: var(--theme-color3);

        > div {
          line-height: 1rem;
          text-align: center;
          width: 30%;

          &.first-one {
            width: 20%;
          }

          &.middle {
            width: 50%;
          }
        }
      }
    }
  }
}

.item-closed {
  .right img {
    transform: rotate(180deg) !important;
  }
  .item-details {
    max-height: 0;
    opacity: 0;
  }
}
</style>
